package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 获取购物车中的菜品或套餐
     *
     * @param shoppingCart
     * @return
     */

    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 添加到购物车
     *
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (user_id,name, image, dish_id, setmeal_id, dish_flavor, amount, create_time,number) VALUES (#{userId},#{name}, #{image}, #{dishId}, #{setmealId}, #{dishFlavor},#{amount}, #{createTime},#{number})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 更新购物车数量
     *
     * @param cartService
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart cartService);

    /**
     * 根据用户id查询购物车
     *
     * @param currentId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{currentId}")
    List<ShoppingCart> getByUserId(Long currentId);

    /**
     * 根据用户id删除购物车数据
     *
     * @param currentId
     */
    @Delete("delete from shopping_cart where user_id = #{currentId}")
    void deleteByUserId(Long currentId);

    /**
     * 购物车中对应菜品或者套餐的数量减一
     *
     * @param shoppingCart
     */
    void deleteOne(ShoppingCart shoppingCart);

    /**
     * 批量插入购物车数据
     *
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
